/** layuiAdmin.std-v1.2.1 LPPL License By http://www.layui.com/admin/ */
layui.define(["table", "form", "pkc", "element", "laypage"], function (e) {
    var t = layui.$,
        i = layui.table,
        r = (layui.form, layui.element),
        layform = layui.form,
        layer = layui.layer,
        pkc = layui.pkc;

    var form = {
        local: {
            fm: null //当前页面form元素
        },
        /**
         * 初始化控件事件
         * */
        initEv: function () {
            //监听提交
            layform.on("submit(fmsub)", function (fm) {
                layform.verify();
                layer.confirm("需要保存数据?", {
                    icon: 3,
                    title: "提示"
                }, function (
                    index
                ) {
                    var ldIndex = layer.load(1);
                    var data = form.getWebParam(fm);
                    form.toolAction.save(data).always(() => {
                        layer.closeAll("loading");
                    });

                    layer.close(index);
                });

                // layer.msg(JSON.stringify(data.field));
                return false;
            });
        },
        /**
         * 界面初始化
         * */
        init: function () {
            this.initEv();
            setTimeout(function () {
                layer.closeAll("loading");
            }, 2000);
        },
        // 编辑
        toolAction: {
            /**
             * 新增
             * */
            save: function (data) {
              return pkc.http.SendPost(
                data,
                "cs.c01.updatepassword",
                function (ret) {
                  if (ret) {
                    ret = JSON.parse(ret);
                    if (ret !== null && ret.Status === "1") {
                      //success
                      layer.msg('操作成功');
                      form.close();
                      //重新加载数据
                      parent.reloadGrid(1, 10);
                    } else {
                      layer.alert(ret.Message);
                    }
                  }
                },
                function (res) {
                  layer.alert("网络异常.请稍后再试！");
                  // layer.closeAll("loading");
                }
              );
            },
            
          },
        getWebParam: function (fmData) {
        fmData = fmData.field;
        var data = {};
        data.id = parent.data.id;
        data.password = fmData.password;
        return data;
        },
        /**
         * 关闭窗体
         */
        close: function () {
            var index = parent.layer.getFrameIndex(window.name);
            setTimeout(function(){
                parent.layer.close(index);
            },2000)
        }
    };

    e("userseteditpsw", {
        init: () => {
            form.init();
        }
    });
});